/*
 *  Copyright 2005 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.persistence.questionnaire;

import com.blandware.atleap.persistence.core.DAO;
import com.blandware.atleap.model.questionnaire.Questionnaire;
import com.blandware.atleap.model.questionnaire.Question;
import com.blandware.atleap.model.questionnaire.AnswerOption;
import com.blandware.atleap.common.util.PartialCollection;
import com.blandware.atleap.common.util.QueryInfo;

/**
 * <p>DAO for answer options.</p>
 * <p><a href="AnswerOptionDAO.java.html"><i>View source</i></a></p>
 *
 * @author Roman Puchkovskiy <a href="mailto:roman.puchkovskiy@blandware.com">
 *         &lt;roman.puchkovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.3 $ $Date: 2006/10/31 11:55:53 $
 */
public interface AnswerOptionDAO extends DAO {

    // ~ CRUD methods ================================================================

    /**
     * Creates a new answer option for a question.
     *
     * @param answerOption answer option to create
     * @param question question to which to put option
     * @return ID of created answer option
     */
    public Long createAnswerOption(AnswerOption answerOption, Question question);

    /**
     * Retrieves an answer option by its ID.
     *
     * @param questionId ID of answer option
     * @return retrieved answer option
     */
    public AnswerOption retrieveAnswerOption(Long questionId);

    /**
     * Updates an answer option.
     *
     * @param answerOption answer option to update
     * @param question question to which option belongs
     */
    public void updateAnswerOption(AnswerOption answerOption, Question question);

    /**
     * Deletes an answer option.
     *
     * @param answerOption option to delete
     */
    public void deleteAnswerOption(AnswerOption answerOption);

    // ~ Additional methods ================================================================

	/**
	 * Retrieves filtered/sorted collection of answer options.
	 *
	 * @param queryInfo Object that contains information about how to filter
     * and sort data
	 * @return Collection of answer options
	 */
    public PartialCollection listAnswerOptions(QueryInfo queryInfo);

    /**
     * Changes an option position so that it becomes one position higher or
     * lower.
     *
     * @param answerOption what answer option to move
     * @param up if true, option is moved up, else down
     */
    public void moveAnswerOption(AnswerOption answerOption, boolean up);

    /**
     * Creates a copy of answer option and places it into a given question.
     *
     * @param answerOption option to copy
     * @param question where to put a copy
     * @return new option
     */
    public AnswerOption copyAnswerOption(AnswerOption answerOption,
                                         Question question);

    /**
     * Returns least and most positions of option which owner has given ID.
     *
     * @param ownerId ID of question which children will be considered
     * @return two-element array: least and most occupied positions
     */
    public Integer[] getFirstLastOccupiedPositions(Long ownerId);
}
